#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int INTMAX = 2147483647;

const int N = 1e5 + 10;
/*
首先：找到一种贪心的方法，就是使得最大的a，b打败其他剩下所有人
首先建立反向边，看哪些点可以到达
然后查找最大a和最大b所能够被哪些点到达，然后求取最小的mina和minb
最后分别看每一个点，查看他们是否大于mina或minb要是大于说明他们能够到达最大a或者最大b也就是能通过最大a或者最大b打败其他剩下的所有人
*/

int n;
PII a[N], b[N];
int ra[N], rb[N];
bool st[N];
vector<int> v[N];
int mina, minb;

void dfs(int u){
    mina = min(ra[u], mina);
    minb = min(rb[u], minb);
    st[u] = true;

    for(int k : v[u]){
        if(!st[k]){
            dfs(k);
        }
    }

}

void solve(){
    mina = INTMAX, minb = INTMAX;
    cin >> n;

    for(int i = 1; i <= n; i ++){
        v[i].clear();
        st[i] = false;
    }

    for(int i = 1; i <= n; i ++){
        cin >> a[i].first;
        a[i].second = i;
        ra[i] = a[i].first;
    }
    for(int i = 1; i <= n; i ++){
        cin >> b[i].first;
        b[i].second = i;
        rb[i] = b[i].first;
    }

    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);

    // for(int i = 1; i <= n; i ++) cout << ra[i] << " ";
    // cout << '\n';
    // for(int i = 1; i <= n; i ++) cout << rb[i] << " ";
    // cout << '\n';
    // exit(0);
    

    for(int i = 2; i <= n; i ++){
        int cur = a[i].second, ne = a[i - 1].second;
        v[ne].push_back(cur);

        cur = b[i].second, ne = b[i - 1].second;
        v[ne].push_back(cur);
    }

    int ma = -1, maid = - 1, mb = -1, mbid = -1;
    for(int i = 1; i <= n; i ++){
        int val = a[i].first, idx = a[i].second;
        if(val > ma){
            ma = val;
            maid = idx;
        }

        val = b[i].first, idx = b[i].second;
        if(val > mb){
            mb = val;
            mbid = idx;
        }
    }

    //maid 代表最大a的节点， mbid 代表最大b的节点
    // 分别搜索他们所能到达的最小的a, b


    for(int i = 1; i <= n; i ++) st[i] = false;
    dfs(maid);
    for(int i = 1; i <= n; i ++) st[i] = false;
    dfs(mbid);

    for(int i = 1; i <= n; i ++){
        if(ra[i] >= mina || rb[i] >= minb){
            cout << 1;
        }else{
            cout << 0;
        }
    }

    cout << '\n';

}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}